package net.jdm.domain.dependence;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import net.jdm.domain.dependence.ClassDependence.ClassDependType;
import net.jdm.domain.entity.Class;
import net.jdm.domain.entity.Package;

public class PackageDependence extends ContainerDependence{
	public PackageDependence(Package from, Package to) {
		super(from, to);
	}
	@Override
	public Package getFrom() {
		return (Package)super.getFrom();
	}
	@Override
	public Package getTo() {
		return (Package)super.getTo();
	}
	public Set<ClassDependence> getClassDependences() {
		Set<ClassDependence> result = new HashSet<ClassDependence>();
		Set<Class> fromClasses = getFrom().getClasses();
		for(Class fromClass:fromClasses){
			Map<ClassDependType,Set<Class>> dependClassesWithType=fromClass.getDependClassesWithType();
			for(ClassDependType classDependType:dependClassesWithType.keySet()){
				Set<Class> toClasses = dependClassesWithType.get(classDependType);
				for(Class toClass:toClasses){
					if(getTo().getClasses().contains(toClass))
						result.add(new ClassDependence(classDependType,fromClass,toClass));
				}
			}
		}
		return result;
	}
}
